package com.littlec.sdk.manager;

import java.util.Map;
import java.util.WeakHashMap;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;


public class ChatManager  {
	private static final Map<XMPPConnection, ChatManager> INSTANCES = new WeakHashMap();

	public static synchronized ChatManager getInstanceFor(
			XMPPConnection connection) {
		ChatManager manager = (ChatManager) INSTANCES.get(connection);
		if (manager == null)
			manager = new ChatManager(connection);
		return manager;
	}

	private ChatManager(XMPPConnection connection) {
//		connection.getChatManager();
//
//		PacketFilter filter = new PacketFilter() {
//			public boolean accept(Packet packet) {
//				if (!(packet instanceof Message)) {
//					return false;
//				}
//				Message.Type messageType = ((Message) packet).getType();
//				return (messageType == Message.Type.chat)
//						|| ((ChatManager.this.normalIncluded) && (messageType == Message.Type.normal));
//			}
//		};
//		connection.addPacketListener(new PacketListener() {
//			public void processPacket(Packet packet) {
//				Message message = (Message) packet;
//				Chat chat;
//				Chat chat;
//				if (message.getThread() == null) {
//					chat = ChatManager.this.getUserChat(message.getFrom());
//				} else {
//					chat = ChatManager.this.getThreadChat(message.getThread());
//				}
//
//				if (chat == null) {
//					chat = ChatManager.this.createChat(message);
//				}
//
//				if (chat == null)
//					return;
//				ChatManager.this.deliverMessage(chat, message);
//			}
//		}, filter);
		INSTANCES.put(connection, this);
	}
}
